package com.example.computer_exam_training_sys.mapper;

import com.example.computer_exam_training_sys.entity.Question;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface QuestionMapper {

    // 新增题目
    @Insert("INSERT INTO questions(point_id, question_type, difficulty, content, answer, analysis, status) " +
            "VALUES (#{pointId}, #{questionType}, #{difficulty}, #{content}, #{answer}, #{analysis}, #{status})")

    int insert(Question question);

    // 根据ID查询题目
    @Select("SELECT * FROM questions WHERE question_id = #{questionId}")
    Question selectById(@Param("questionId") Integer questionId);

    // 根据知识点ID查询题目
    @Select("SELECT * FROM questions WHERE point_id = #{pointId}")
    List<Question> selectBypointId(@Param("pointId") Integer pointId);

    // 查询全部题目
    @Select("SELECT * FROM questions")
    List<Question> selectAll();

    // 修改题目
    @Update("UPDATE questions SET point_id=#{pointId}, question_type=#{questionType}, difficulty=#{difficulty}, " +
            "content=#{content}, answer=#{answer}, analysis=#{analysis}, status=#{status} " +
            "WHERE question_id=#{questionId}")
    int update(Question question);

    // 删除题目
    @Delete("DELETE FROM questions WHERE question_id = #{questionId}")
    int delete(@Param("questionId") Integer questionId);

    @Select("SELECT question_id FROM questions WHERE point_id = #{pointId} LIMIT 1")
    Integer getFirstQuestionIdByPointId(@Param("pointId") Integer pointId);
}
